#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, q;
string a;
int seat[100010], id2;
int number1[100010], number2[100010];

inline int ans(int l, int mid, int r) {
	return min(number2[r] - number2[mid], number1[mid] - number1[l - 1]) * 2 + 1;
}
signed main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> q >> a;
	a = " " + a;
	for (int i = 1; i <= n; i++) {
		number1[i] = number1[i - 1];
		number2[i] = number2[i - 1];
		if (a[i] == '/') {
			seat[++id2] = i;
		} else if (a[i] == '1') {
			number1[i]++;
		} else {
			number2[i]++;
		}
	}
	seat[id2 + 1] = 1e18;
	while (q--) {
		int l, r;
		cin >> l >> r;
		int p = lower_bound(seat + 1, seat + 1 + id2, l) - seat;
		if (seat[p] < l || seat[p] > r) {
			cout << "0\n";
		} else {
			int k = upper_bound(seat + 1, seat + 1 + id2, r) - seat - 1;
			int ll = p, rr = k;
			while (ll < rr) {
				int mid = ll + rr >> 1;
				if (number1[seat[mid]] - number1[l - 1] < number2[r] - number2[seat[mid]]) {
					ll = mid + 1;
				} else {
					rr = mid;
				}
			}
			int res = ans(l, seat[ll], r);
			if (seat[ll - 1] >= l && seat[ll - 1] <= r)
				res = max(res, ans(l, seat[ll - 1], r));
			cout << res << "\n";
		}
	}
	return 0;
}